﻿
#define FPS

using UnityEngine;
using System.Collections;
using UnityEditor;

public class FPSDisplay : MonoBehaviour
{
#if FPS
	float deltaTime = 0.0f;

	void Update()
	{
		deltaTime += (Time.unscaledDeltaTime - deltaTime) * 0.1f;
	}

	void OnGUI()
	{
		int w = Screen.width, h = Screen.height;
		//float msec = deltaTime * 1000.0f;
		float fps = 1.0f / deltaTime;

		GUIStyle style = new GUIStyle();
		Rect rect = new Rect(5, 5, w, h * 2 / 100);
		style.alignment = TextAnchor.UpperLeft;
		style.fontSize = h * 2 / 100;
        //new Color (0.0f, 0.0f, 0.5f, 1.0f);
        Color color = Color.green;
		if (fps < 45) { color = Color.yellow; }
		else if (fps < 30) { color = Color.red; }
		style.normal.textColor = color;
		
		string text = string.Format("FPS:{0:0.}", fps);
		GUI.Label(rect, text, style);
	}
#endif

}